package o;

import java.io.Serializable;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Objects;

public final class cjs {

    static final class e implements ParameterizedType, Serializable {
        private final Type ˊ;
        private final Type[] ˋ;
        private final Type ˎ;

        public e(Type type, Type type2, Type... typeArr) {
            int i = 0;
            if (type2 instanceof Class) {
                boolean z;
                Class cls = (Class) type2;
                int i2 = (Modifier.isStatic(cls.getModifiers()) || cls.getEnclosingClass() == null) ? 1 : 0;
                if (type == null && i2 == 0) {
                    z = false;
                } else {
                    z = true;
                }
                ˎ(z);
            }
            this.ˎ = type == null ? null : cjs.ˋ(type);
            this.ˊ = cjs.ˋ(type2);
            this.ˋ = (Type[]) typeArr.clone();
            while (i < this.ˋ.length) {
                ˏ(this.ˋ[i]);
                ˏ(this.ˋ[i]);
                this.ˋ[i] = cjs.ˋ(this.ˋ[i]);
                i++;
            }
        }

        private static void ˎ(boolean z) {
            if (!z) {
                throw new IllegalArgumentException();
            }
        }

        private static <T> T ˏ(T t) {
            if (t != null) {
                return t;
            }
            throw new NullPointerException();
        }

        private static String ˎ(Type type) {
            return type instanceof Class ? ((Class) type).getName() : type.toString();
        }

        public Type[] getActualTypeArguments() {
            return (Type[]) this.ˋ.clone();
        }

        public Type getRawType() {
            return this.ˊ;
        }

        public Type getOwnerType() {
            return this.ˎ;
        }

        private void ˏ(Type type) {
            boolean z = ((type instanceof Class) && ((Class) type).isPrimitive()) ? false : true;
            ˎ(z);
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof ParameterizedType)) {
                return false;
            }
            obj = (ParameterizedType) obj;
            if (this == obj) {
                return true;
            }
            Type ownerType = obj.getOwnerType();
            Type rawType = obj.getRawType();
            if (Objects.equals(this.ˎ, ownerType) && Objects.equals(this.ˊ, rawType) && Arrays.equals(this.ˋ, obj.getActualTypeArguments())) {
                return true;
            }
            return false;
        }

        public int hashCode() {
            return (this.ˎ == null ? 0 : this.ˎ.hashCode()) ^ (this.ˊ.hashCode() ^ Arrays.hashCode(this.ˋ));
        }

        public String toString() {
            StringBuilder stringBuilder = new StringBuilder((this.ˋ.length + 1) * 30);
            stringBuilder.append(ˎ(this.ˊ));
            if (this.ˋ.length == 0) {
                return stringBuilder.toString();
            }
            stringBuilder.append("<").append(ˎ(this.ˋ[0]));
            for (int i = 1; i < this.ˋ.length; i++) {
                stringBuilder.append(", ").append(ˎ(this.ˋ[i]));
            }
            return stringBuilder.append(">").toString();
        }
    }

    public static Class<?> ॱ(Type type) {
        if (type instanceof Class) {
            return (Class) type;
        }
        if (type instanceof ParameterizedType) {
            return (Class) ((ParameterizedType) type).getRawType();
        }
        if (type instanceof TypeVariable) {
            TypeVariable typeVariable = (TypeVariable) type;
            if (typeVariable.getBounds().length == 0) {
                return Object.class;
            }
            return ॱ(typeVariable.getBounds()[0]);
        }
        throw new IllegalArgumentException("not supported: " + type.getClass());
    }

    public static <T> Class<T> ˏ(Class<T> cls) {
        Type genericSuperclass = cls.getGenericSuperclass();
        while (!(genericSuperclass instanceof ParameterizedType)) {
            cls = cls.getSuperclass();
            genericSuperclass = cls.getGenericSuperclass();
        }
        return ॱ(((ParameterizedType) genericSuperclass).getActualTypeArguments()[0]);
    }

    public static Type ॱ(Type type, Class<?> cls, Type type2) {
        Type type3 = type2;
        while (type3 instanceof TypeVariable) {
            type3 = (TypeVariable) type3;
            type2 = ˊ(type, cls, type3);
            if (type2 == type3) {
                return type2;
            }
            type3 = type2;
        }
        if (!(type3 instanceof ParameterizedType)) {
            return type3;
        }
        ParameterizedType parameterizedType = (ParameterizedType) type3;
        Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
        int length = actualTypeArguments.length;
        Type[] typeArr = actualTypeArguments;
        Object obj = null;
        Type[] typeArr2 = typeArr;
        for (int i = 0; i < length; i++) {
            Type ॱ = ॱ(type, cls, typeArr2[i]);
            if (ॱ != typeArr2[i]) {
                if (obj == null) {
                    typeArr2 = (Type[]) typeArr2.clone();
                    obj = 1;
                }
                typeArr2[i] = ॱ;
            }
        }
        if (obj != null) {
            return new e(null, parameterizedType.getRawType(), typeArr2);
        }
        return parameterizedType;
    }

    public static Type ˊ(Type type, Class<?> cls, TypeVariable<?> typeVariable) {
        Class ˊ = ˊ(typeVariable);
        if (ˊ == null) {
            return typeVariable;
        }
        Type ˏ = ˏ(type, cls, ˊ);
        if (!(ˏ instanceof ParameterizedType)) {
            return typeVariable;
        }
        return ((ParameterizedType) ˏ).getActualTypeArguments()[ॱ(ˊ.getTypeParameters(), typeVariable)];
    }

    private static Class<?> ˊ(TypeVariable<?> typeVariable) {
        GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
        return genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
    }

    static Type ˏ(Type type, Class<?> cls, Class<?> cls2) {
        if (cls2 == cls) {
            return type;
        }
        if (cls2.isInterface()) {
            Class[] interfaces = cls.getInterfaces();
            int length = interfaces.length;
            for (int i = 0; i < length; i++) {
                if (interfaces[i] == cls2) {
                    return cls.getGenericInterfaces()[i];
                }
                if (cls2.isAssignableFrom(interfaces[i])) {
                    return ˏ(cls.getGenericInterfaces()[i], interfaces[i], cls2);
                }
            }
        }
        if (!cls.isInterface()) {
            while (cls != Object.class) {
                Class<?> superclass = cls.getSuperclass();
                if (superclass == cls2) {
                    return cls.getGenericSuperclass();
                }
                if (cls2.isAssignableFrom(superclass)) {
                    return ˏ(cls.getGenericSuperclass(), superclass, cls2);
                }
                cls = superclass;
            }
        }
        return cls2;
    }

    private static int ॱ(Object[] objArr, Object obj) {
        for (int i = 0; i < objArr.length; i++) {
            if (obj.equals(objArr[i])) {
                return i;
            }
        }
        throw new NoSuchElementException();
    }

    public static Type ˋ(Type type) {
        if (type instanceof Class) {
            return (Class) type;
        }
        if (!(type instanceof ParameterizedType)) {
            return type;
        }
        ParameterizedType parameterizedType = (ParameterizedType) type;
        return new e(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
    }
}
